// @ts-nocheck
// 引入axios发送请求
const { resolve } = require('path');
const axios = require('axios');
const { getInput } = require(resolve('./lib/readline/index.js'));
const env = require(resolve('./config.js'));
const dp = env[env.mode];
console.log(dp);

function getJobUrl() {
    return new Promise(async(resolve, reject) => {
        let res = [],
            promises = null;
        key = await getInput();
        let timer = setInterval(async() => {
            console.log(`${dp[res.length].city}———${key}职位信息获取中，请等待...`);
            promise = axios.get("https://www.liepin.com/zhaopin/", {
                params: {
                    sfrom: 'search_job_pc',
                    key,
                    dq: dp[res.length].code,
                    scene: 'input',
                }
            })
            res.push(promise);
            if (res.length == dp.length) {
                clearInterval(timer);
                console.log('请求发送完毕！');
                resolve({ res, key });
            }
        }, 5000)
    })
}

/* getJobUrl().then((value) => {
    console.log(value);
    console.log(value.length);
}) */
module.exports = {
    getJobUrl
}